﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Register.IDAL;
using Register.DALFactory;
using Register.Command;
using Register.Model;
using System.Data;

namespace Register.BLL
{
    /// <summary>
    /// FileName: HospitalInfoBLL.cs
    /// CLRVersion: 4.0.30319.269
    /// Author: WangYan
    /// Corporation: 
    /// Description: 
    /// DateTime: 2012/6/26 14:12:16
    /// </summary>
  public  class HospitalInfoBLL
    {
      private static string typeNameKey = "IHospitalInfoDALKey";
     

      public HospitalInfoBLL()
      { }
      #region  Method
      public static bool AddHospitalInfo(Model.HospitalInfo model)
      {
          IHospitalInfoDAL iAdminInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);
          try
          {
              if (iAdminInfo.AddHospitalInfo(model) > 0)
                  return true;
              else
                  return false;
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      //删除
      public static bool DeleteHospitalInfo(string hospitalID)
      {
          IHospitalInfoDAL iHospitalInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);
          try
          {
              if (iHospitalInfo.DeleteHospitalInfo(hospitalID) > 0)
                  return true;
              else
                  return false;
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      //更新
      public static bool UpdateHospitalInfo(Model.HospitalInfo model)
      {
          IHospitalInfoDAL iHospitalInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);
          try
          {
              if (iHospitalInfo.UpdateAdminInfo(model) > 0)
              {
                  return true;
              }
              else
                  return false;
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }

      public static bool Exists(string doctorID)
      {
          IHospitalInfoDAL iHospitalInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);

          try
          {
              bool flag = iHospitalInfo.Exists(doctorID);
              return flag;
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }

      public static string GetParamNameById(string paramID)
      {
          IHospitalInfoDAL iHospitalInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);
          try
          {
              return iHospitalInfo.GetParamNameById(paramID);

          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }

      /// <summary>
      /// 获得数据列表
      /// </summary>
      public static List<HospitalInfo> DataTableToList(DataTable dt)
      {
          List<HospitalInfo> modelList = new List<HospitalInfo>();
          int rowsCount = dt.Rows.Count;
          if (rowsCount > 0)
          {
              HospitalInfo model;
              for (int n = 0; n < rowsCount; n++)
              {
                  model = new HospitalInfo();
                  model.Hospital_ID = dt.Rows[n]["Hospital_ID"].ToString();
                  model.City_ID = dt.Rows[n]["City_ID"].ToString();
                  model.Hospital_No = dt.Rows[n]["Hospital_No"].ToString();
                  model.Hospital_Name = dt.Rows[n]["Hospital_Name"].ToString();
                  model.Hospital_Level = dt.Rows[n]["Hospital_Level"].ToString();
                  model.Hospital_Nature = dt.Rows[n]["Hospital_Nature"].ToString();
                  model.Hospital_Type = dt.Rows[n]["Hospital_Type"].ToString();
                  model.Hospital_Address = dt.Rows[n]["Hospital_Address"].ToString();
                  model.Hospital_Phone = dt.Rows[n]["Hospital_Phone"].ToString();
                  model.Hospital_Website = dt.Rows[n]["Hospital_Website"].ToString();
                  model.Hospital_Introduce = dt.Rows[n]["Hospital_Introduce"].ToString();
                  model.Hospital_Logo = dt.Rows[n]["Hospital_Logo"].ToString();
                  if (dt.Rows[n]["Hospital_AddTime"].ToString() != "")
                  {
                      model.Hospital_AddTime = DateTime.Parse(dt.Rows[n]["Hospital_AddTime"].ToString());
                  }
                  model.Hospital_Recoder = dt.Rows[n]["Hospital_Recoder"].ToString();
                  if (dt.Rows[n]["Hospital_LastAmendTime"].ToString() != "")
                  {
                      model.Hospital_LastAmendTime = DateTime.Parse(dt.Rows[n]["Hospital_LastAmendTime"].ToString());
                  }
                  model.Hospital_LastAmendPerson = dt.Rows[n]["Hospital_LastAmendPerson"].ToString();
                  model.Hospital_State = dt.Rows[n]["Hospital_State"].ToString();
                  modelList.Add(model);
              }
          }
          return modelList;
      }

      /// <summary>
      /// 获得数据列表
      /// </summary>
      /* public static DataSet GetAllList()
        {
            IHospitalInfo iDictionary = DALFactory<IHospitalInfo>.Create(typeNameKey);
            return iDictionary.GetList("");
       }
        */
      /// <summary>
      /// 分页获取数据列表
      /// </summary>

      public static List<Model.HospitalInfo> GetPagedHospitalInfo(int size, int pageIndex, string where)
      {
          IHospitalInfoDAL iHospitalInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);
          try
          {
              return iHospitalInfo.GetPagedHospitalInfo(size, pageIndex, where);
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      public static int GetHospitalInfoCount(string where)
      {
          IHospitalInfoDAL iAdminInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);

          try
          {
              return iAdminInfo.GetHospitalInfoCount(where);
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      #endregion  Method


     public static List<Model.HospitalInfo> GetHospitalInfos()
      {
          IHospitalInfoDAL iAdminInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);

          try
          {
              return iAdminInfo.GetHospitalInfos();
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR",e.Message);
              throw e;
          }

      }
      
     public static HospitalInfo GetHospitalInfoByID(string Hospital_ID)
      {
          IHospitalInfoDAL iAdminInfo = DALFactory<IHospitalInfoDAL>.Create(typeNameKey);

          try
          {
              return iAdminInfo.GetHospitalInfoByID(Hospital_ID);
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      

    }
}
